# -*- coding: utf-8 -*-     
import logging

from odoo import http
from odoo.http import request
from odoo.tools import topological_sort
from odoo.tools.translate import _
_logger = logging.getLogger(__name__)

fhname = "fhname"

class WebSettingsDashboard002(http.Controller):

    @http.route('/web_widget_iframe/data2', type='json', auth="public")
    def web_settings_dashboard_data002(self, debug=False, **k):
        return {
            'uid002': request.session.uid002,
			'password002': request.session.password002,
			'organion_code': request.session.organion_code,
        }  

    # 监控点和区域信息
    @http.route('/web_form_tree/addtree/<string:fhmodel>/<string:fhp_field>', auth='public', website=True)
    def pamaddtree(self, fhmodel=None, fhp_field=None):
        lself = http.request.env[fhmodel].search([(fhp_field, "=", False)])
        result = []
        for odoj in lself:
            name = ""
            if (1==1):
                result.append({
                    'id': odoj.id, 'pId': 0,
                    #'fhtype': odoj["fhtype"],
                    'value': odoj[fhname]  +'[' + str(odoj.id) + ']',
                    'name':  odoj[fhname] +'[' + str(odoj.id) + ']',
                    'file': odoj.id,
                    'open': 'true',
                    #'icon': '/tmmp/static/ztree/icon/jiemian.png',
                })

            result = result + self.name_getII(odoj.id, odoj["id"],fhmodel,fhp_field)
        return str(result)

    def name_getII(self, fkid, fk_parent_code,fhmodel,fhp_field):
        result = []
        lself = http.request.env[fhmodel]
        lcount0 = lself.search_count([(fhp_field, "=", fk_parent_code)])
        ZGself = lself.search([(fhp_field, "=", fk_parent_code)])
        if (lcount0 <= 0):
            return [];
        for odoj in ZGself:
            print(odoj.id)
            if (1==1):
                result.append({
                    'id': odoj.id, 'pId': fkid,
                    #'fhtype': odoj["fhtype"],
                    'value':  odoj[fhname] +'[' + str(odoj.id) + ']',
                    'name': odoj[fhname]+'[' + str(odoj.id) + ']',
                    'file': odoj.id,
                    'open': 'true',
                   # 'icon': '/tmmp/static/ztree/icon/jiemian.png',
                })

 
            result = result + self.name_getII(odoj.id,odoj.id,fhmodel,fhp_field)
        return result        